package com.campus.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.campus.entry.CourseLearnUnit;
import com.campus.pojo.dto.CourseLearnUnitDto;
import com.campus.pojo.dto.StudentLearningUnitDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.security.core.parameters.P;

import java.util.List;

@Mapper
public interface CourseLearnUnitMapper extends BaseMapper<CourseLearnUnit> {

    @Select("SELECT cu.id AS id, cu.unit_title AS unitTitle, cu.video_path AS videoPath, cu.unit_introduce AS unitIntroduce, cu.status AS status, " +
            "c.course_name AS courseName " +
            "FROM t_course_learn_unit cu " +
            "JOIN t_course c ON cu.course_id = c.id " +
            "WHERE c.teacher_id = #{teacherId}")
    List<CourseLearnUnitDto> selectCourseLearnUnitsByTeacherId(int teacherId);
    @Update("update t_course_learn_unit set status=#{status} where id=#{id}")
   void updateState(@Param("id") Integer id, @Param("status") Integer status);
    List<CourseLearnUnitDto> selectByConditions(@Param("teacherId") Integer teacherId,@Param("unitTitle") String unitTitle, @Param("status") Integer status);

    @Select("   SELECT \n" +
            "        tclu.id AS unitId,                   \n" +
            "        tclu.unit_title AS unitTitle,        \n" +
            "        tclu.doc_path AS docPath,            \n" +
            "        tclu.video_path AS videoPath,        \n" +
            "        tclu.unit_introduce AS unitIntroduce, \n" +
            "        tclu.learning_score AS score ,        \n" +
            "         t.course_name As courseName  \n        "+
            "    FROM \n" +
            "        t_teaching_student_in_class tsic\n" +
            "    JOIN \n" +
            "        t_manager_class tc ON tsic.class_id = tc.id  \n" +
            "    JOIN \n" +
            "        t_course t ON tc.activity_id = t.activity_id \n" +
            "    JOIN \n" +
            "        t_course_learn_unit tclu ON t.id = tclu.course_id  \n" +
            "    WHERE \n" +
            "        tsic.student_id = #{studentId}")
    List<StudentLearningUnitDto> getLearningUnitsByStudentId(@Param("studentId") Integer studentId);
}
